package cn.mldn.experiment.BIOwithMultiThread;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class BIOClient{
    public static void main(String[] args) throws UnknownHostException,IOException
    {
    	Socket socket=new Socket("localhost",8888);
    	
    	OutputStream outputStream=socket.getOutputStream();
    	InputStream inputStream=socket.getInputStream();
    	
    	Scanner scanner =new Scanner(System.in);
    	System.out.println("请输入要发送的信息：");
    	
    	while(scanner.hasNext())
    	{
    		String msg =scanner.nextLine();
    		outputStream.write(msg.getBytes());
    		
    		byte[] b=new byte[1024];
    		int len =inputStream.read(b);
    		if(len==-1)
    		{
    			break;
    		}
    		
    		System.out.println("收到服务器的信息："+new String (b,0,len));
    		System.out.println("请输入要发送的信息：");
    	}
    	
    	scanner.close(); // 关闭输入流
    	socket.close(); // 关闭客户端
    }
}